/*
 * @Date: 2022-03-16 20:36:29
 * @Author: 1365595476@qq.com
 * @LastEditors: 1365595476@qq.com
 * @LastEditTime: 2022-03-17 00:51:20
 */
import { defineConfig } from 'vite'

import { resolve } from 'path'

import react from '@vitejs/plugin-react'

/*
  https://www.npmjs.com/package/@vitejs/plugin-legacy
  解决传统浏览器不支持ESM打包问题
*/
import legacy from '@vitejs/plugin-legacy'

/*
  https://www.npmjs.com/package/vite-plugin-imp
  一个自动导入组件库样式的vite插件
*/
import vitePluginImp from 'vite-plugin-imp'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(),
    legacy({
      targets: ['ie >= 11'],
      // 面向IE11时需要此插件
      additionalLegacyPolyfills: ['regenerator-runtime/runtime']
    }),
    vitePluginImp({
      libList: [
        {
          libName: 'antd',
          style: name => `antd/es/${name}/style`
        }
      ]
    })
  ],
  resolve: {
    alias: {
      '~': resolve(__dirname, './'),
      '@': resolve(__dirname, 'src')
    }
  },
  css: {
    preprocessorOptions: {
      less: {
        // modifyVars: { 'primary-color': '#13c2c2' },
        javascriptEnabled: true
      }
    }
  }
})
